// mircoApp/idShop/idShop_apply_enterprise/idShop_apply_enterprise.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl: "",
    imageUrl2: "",
    idCard: "",
    mobile: "",
    license_pic_file_name: "",
    license_pic: "",
    applyStatus: "",
    auth_contract: "",
    auth_contract_file_name: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onRead_a(event) {
    wx.showLoading({
      title: '上传中'
    })
    const {
      file
    } = event.detail;
    let urlStr = app.getNetAddresss("upload.uploadPic");
    wx.uploadFile({
      url: urlStr,
      filePath: file.url,
      name: 'file',
      success: (resdata) => {
        app.tips("上传成功")
        let res = JSON.parse(resdata.data);
        console.log(resdata, res, file)
        this.setData({
          license_pic: res.data.img_url,
          license_pic_file_name: res.data.img,
          imageUrl: res.data.img_url
        })
        wx.hideLoading();
      },
      fail(err) {
        app.tips("上传失败")
        wx.hideLoading();
      },
      complete() {
        wx.hideLoading();
      }

    });
  },
  onRead2(event) {
    wx.showLoading({
      title: '上传中'
    })
    const {
      file
    } = event.detail;
    let urlStr = app.getNetAddresss("upload.uploadPic");
    wx.uploadFile({
      url: urlStr,
      filePath: file.url,
      name: 'file',
      success: (resdata) => {
        app.tips("上传成功")
        let res = JSON.parse(resdata.data);
        console.log(resdata, res, file)
        this.setData({
          auth_contract: res.data.img_url,
          auth_contract_file_name: res.data.img,
          imageUrl2: res.data.img_url
        })
        wx.hideLoading();
      },
      fail(err) {
        app.tips("上传失败")
        wx.hideLoading();
      },
      complete() {
        wx.hideLoading();
      }

    });
  },
  toRecord() {
    wx.navigateTo({
      url: '/mircoApp/idShop/idShop_apply_enterprise_record/idShop_apply_enterprise_record'
    })
  },
  async getData() {
    let {
      data
    } = await app._getNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.apply.companyApplyCheck"),
    })
    if (data.result) {
      this.setData({
        applyStatus: data.data.status,
        image_url_status: data.data.image_url
      })
    } else {
      this.setData({
        applyStatus: 2
      })
    }
  },
  async applySubmit() {
    let json = {
      form: {
        license_pic_file_name:this.data.license_pic_file_name,
        license_pic: this.data.license_pic,
        auth_contract: this.data.auth_contract,
        auth_contract_file_name:this.data.auth_contract_file_name,
        manager_tel: this.data.mobile,
        manager_code: this.data.idCard
      }
    }
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.apply.companyApply"),
      data: json
    })
    if (data.result) {
      app.tips(data.msg)
      this.getData();
    } else {
      app.tips(data.msg)
    }
  }
})